package Account;

/**
 * @author: zxy
 * @date: 2024/5/20 18:43
 * @version: 1.0
 */
public class CheckAccount extends Account {

    private double overdraft;

    public CheckAccount(int id, double balance, double annuallnterestRate) {
        super(id, balance, annuallnterestRate);
    }

    public CheckAccount(int id, double balance, double annuallnterestRate, double overdraft) {
        super(id, balance, annuallnterestRate);
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(double amount) {
        if (amount < getBalance()){
            setBalance(getBalance() - amount);
            System.out.println("已取款：" + amount + "\t" + "账户余额：" + getBalance() + "\t" + "可透支额为：" + overdraft);
        }
        else {
            if (amount < overdraft + getBalance()){
                setOverdraft(overdraft - (amount - getBalance()));
                setBalance(0);
                System.out.println("已取款：" + amount + "\t" + "账户余额：" + getBalance() + "\t" + "可透支额为：" + overdraft);
            }
            else {
                System.out.println("取款失败，取款金额超出可透支额度");
            }
        }
    }

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }
}
